<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>
<body>
  <div id="app">
    <ul>
      <li v-for="(film,index) in films" :key="film.filmId">
        <h5>
          电影名：{{ film.name }}
        </h5>
        <p>
          简介：{{ film.synopsis }}
        </p>
        <p>
          <img :src="film.poster" alt="">
        </p>
        <p>
          类型：
          {{ film.item.name }}
        </p>
      </li>
    </ul>
  </div>
  <script  src="./axios.js"></script>
  <script>
    // 创建一个 axios 实例
    const request = axios.create({
      // 可以做 请求初始化配置
      baseURL: "https://m.maizuo.com",
      timeout:5000,
      headers:{
        "X-Client-Info":'{"a":"3000","ch":"1002","v":"5.0.4","e":"1597720815568988677439489","bc":"110100"}',
        "X-Host":"mall.film-ticket.film.list"
      }
    });

    
// 添加 请求 拦截器
request.interceptors.request.use(function (config) {
    // 可以在请求发送之前做一些事情  config 请求信息 config.headers 
    console.log("发送之前走这里");
    console.log(config);
   
    return config;
  }, function (error) {
    // 出错了 走这里
    return Promise.reject(error);
  });

// 添加相应拦截
request.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // 在相应数据 发送到 ajax之前，可以在这里拦截
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

    let vm = new Vue({
      el:"#app",
      data:{
        films:[]
      },
      created(){
        this.fetchFilms();
      },
      methods:{
        fetchFilms(){// 请求数据方法
          request.get("/gateway",{
            params:{
              cityId:"110100",
              pageNum:1,
              pageSize:10,
              type:1,
              k:492559
            }
          }).then(res=>{
            if(res.data.status === 0){
              this.films = res.data.data.films;
            }
          })
        }
      }
    })

   
  </script>
</body>
</html>